<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>评测列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="./lib/css/layui.css" media="all">
</head>

<body>
    <!-- 查询 -->
    <form class="layui-form layui-row" action="" lay-filter="tableFilter" style="width: 90%;">
        <div class="layui-col-xs3 layui-form-item">
            <label class="layui-form-label">会员编号:</label>
            <div class="layui-input-block">
                <input type="text" name="member_no" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-col-xs3 layui-form-item ">
            <label class="layui-form-label">姓名:</label>
            <div class="layui-input-block">
                <input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-col-xs3 layui-form-item ">
            <label class="layui-form-label">班级:</label>
            <div class="layui-input-block">
                <input type="text" name="className" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-col-xs3">
            <div class="layui-input-block">
                <button lay-submit lay-filter="search" class="layui-btn layui-btn-normal">查询</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <!-- 表格 -->
    <table class="layui-hide" id="mainTable" lay-filter="mainTable"></table>
    <div>
        <!-- 编辑 -->
        <div id="historyPage" style="width:800px;height: 650px;display: none;">
        </div>
        <!-- 编辑结束 -->
    </div>
    <script src="./lib/layui.js" charset="utf-8"></script>
    <script src="./config.js"></script>
    <script src="./lib/base64.js"></script>
    <script type="text/html" id="tableOperation">
  <button type="button" class="layui-btn layui-btn-sm layui-btn-normal showHistory" lay-event="viewHistory">
    查看历史
  </button>
  <button type="button" class="layui-btn layui-btn-sm layui-btn-success" lay-event="viewReport">
    查看报告
  </button>
  <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" lay-event="printReceipts">
    打印小票
  </button>
</script>
    <script>
        var currrowId = "";
        var isShowHistory = false;
        function getQueryString(name) {
            var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
            var r = window.location.search.substr(1).match(reg);
            if (r != null) {
                return unescape(r[2]);
            }
            return null;
        }
        layui.use(['table', "form", "layer", "jquery", "laydate"], function () {
            var table = layui.table;
            var form = layui.form;
            var $ = layui.$;
            var laydate = layui.laydate;
            var layer = layui.layer;
            table.render({
                elem: '#mainTable'
                , headers: { Authorization: "bearer " + getQueryString('token') }
                , request: { pageName: "pageIndex", limitName: "pageSize" }
                , parseData: function (res) {
                    for (var i = 0; i < res.content.length; i++) {
                        for (var j = 1; j <= res.content[i].data.length; j++) {
                            res.content[i]["item" + j] = res.content[i].data[j - 1].level
                        }
                    }
                    return { code: "0", msg: "ok", data: res.content, count: res.totalElements }
                }
                , page: true
                , url: requestUrl + '/service/focus-service/device/tests'
                , cellMinWidt0h: 50 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                , cols: [[
                    { type: 'numbers', width: 80, title: '序号', width: 80 , fixed: "left"}
                    , { field: 'member_no', title: '会员编号', width: 100, fixed: "left" }
                    , { field: 'name', title: '姓名', width: 100 , fixed: "left"}
                    , { field: 'showAge', title: '年龄', width: 100 }
                    // , { field: 'birth', title: '生日', }
                    , { field: 'sex', title: '性别', width: 60 }
                    , { field: "className", title: "班级", width: 180, templet: function (d) { return d.className ? `${d.className}(${d.classYear})` : "" } }
                    , { field: "check_type", title: "评测类型", width: 100, templet: function (d) { return d.check_type == "1" ? "复核测评" : "默认评测" } }
                    , { field: "teacher", title: "评测老师", width: 100 }
                    , { field: "testDate", title: "测评日期", width: 170 }
                    , { field: "item1", title: "听觉广度", width: 90 }
                    , { field: "item2", title: "听觉记忆", width: 90 }
                    , { field: "item3", title: "听觉加工", width: 90 }
                    , { field: "item4", title: "听觉稳定", width: 90 }
                    , { field: "item5", title: "视觉分辨", width: 90 }
                    , { field: "item6", title: "视觉广度", width: 90 }
                    , { field: "item7", title: "视觉记忆", width: 90 }
                    , { field: "item8", title: "手部控制", width: 90 }
                    , { field: "item9", title: "视觉加工", width: 90 }
                    , { title: "操作", width: 280, templet: "#tableOperation", fixed: "right" }
                ]]
                , done: function (res, curr, count) {
                    if (isShowHistory)
                        $(".showHistory").hide();
                }
            });
            table.on('tool(mainTable)', function (obj) {
                switch (obj.event) {
                    case "viewHistory":
                        table.reload("mainTable", { where: { memberId: obj.data.memberId,pageIndex:1 } });
                        isShowHistory = true;
                        break;
                    case "viewReport":
                        var url =
                            layer.open({
                                type: 2,
                                skin: "layui-layer-rim", //加上边框
                                content: "./report.html?id=" + obj.data.pid,
                                area: ["930px", "90%"],
                                title: "查看报告"
                            });
                        break;
                    case "printReceipts":
                        var o = {
                            "name": obj.data.name,
                            "age": obj.data.showAge,
                            "sex": obj.data.sex,
                            "pid": obj.data.pid,
                            "testtime": obj.data.testDate,
                            "averageScore": obj.data.averageScore + '',
                            "score1": "听觉广度:" + obj.data.data[0].level,
                            "score2": "听觉记忆:" + obj.data.data[1].level,
                            "score3": "听觉加工:" + obj.data.data[2].level,
                            "score4": "听觉稳定:" + obj.data.data[3].level,
                            "score5": "视觉分辨:" + obj.data.data[4].level,
                            "score6": "视觉广度:" + obj.data.data[5].level,
                            "score7": "视觉记忆:" + obj.data.data[6].level,
                            "score8": "手部控制:" + obj.data.data[7].level,
                            "score9": "视觉加工:" + obj.data.data[8].level
                        }
                        var param = Base64.encode(JSON.stringify(o));
                        location.href = "http://print/parm=" + param;
                        break;
                }
            });
            form.on("submit(search)", function (data) {
                table.reload("mainTable", { where: data.field });
                isShowHistory = false;
                return false;
            })
        });
        function request($, type, url, data, success) {
            $.ajax({
                url: url,
                data: data,
                type: type,
                headers: { Authorization: "bearer " + getQueryString('token') },
                success: function (res) {
                    success(res)
                }
            })
        }        
    </script>
</body>
<style>
    .layui-form-item {
        clear: inherit;
    }
</style>

</html>